/*
 * Control.java
 * Team qq 2011
 */
package com.google.code.timetrail.backend;

import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Logger;

/**
 * Acts as the controller for the game as it contains all 
 * the objects that make up the game
 * (will be a singleton in the future)
 * @author Anuraag
 * @version 1.0
 *
 */

public class Control {
	
	/** The logger for this class */
	public static final Logger LOGGER = Logger.getLogger(Control.class);
	
	/** The "main character" of the game*/
	private Person player;
    
	/** The party of people in your ship*/
	private List<Person> members;

    /** The player's Inventory*/
	private Inventory inv;
    
	/** The pace at which the ship is currently moving*/
	private TravelSpeed pace;
    
	/** The rate at which the party is consuming food*/
	private ConsumptionRate rations;
    
	/** The ship the party is currently in*/
	private Spaceship ship;
	
	/**
	 * Instantiates all the starting objects to their default state
	 */
	public Control() {
		player = new Person();
		members = new ArrayList<Person>();
		inv = new Inventory();
		pace = TravelSpeed.STOPPED;
		rations = ConsumptionRate.NONE;
		ship = new Spaceship();
		PropertyConfigurator.configure("time.properties");
		LOGGER.info("Controller Initialized");
	}
	
	/**
	 * Gets the player object from Control
	 * @return the player
	 */
	public Person getPlayer(){
		LOGGER.debug(player + " retrieved from the Controller.");
		return player;
	}
	
	/**
	 * returns the list of members in the space ship's party
	 * @return members
	 */
	public List<Person> getMembers(){
		LOGGER.debug(members + " retrieved from the Controller.");
		return members;
	}
	
	/**
	 * returns the party's current Inventory
	 * @return inv
	 */
	public Inventory getInv(){
		LOGGER.debug("\nInventory containing:\n" + inv 
				+ "\nretrieved from the Controller.");
		return inv;
	}
	
	/**
	 * Returns the pace at which the ship is currently traveling
	 * @return pace
	 */
	public TravelSpeed getPace(){
		LOGGER.debug(pace + " retrieved from the Controller.");
		return pace;
	}
	
	/**
	 * Returns the rate at which the party is consuming food
	 * @return rations
	 */
	public ConsumptionRate getRations(){
		LOGGER.debug(rations + " retrieved from the Controller.");
		return rations;
	}
	
	/**
	 * Returns the spaceship that the party is currently in
	 * @return ship
	 */
	public Spaceship getShip(){
		LOGGER.debug(ship + " retrieved from the Controller.");
		return ship;
	}
	
	/**
	 * Sets the main character of the game
	 * @param player the player to become the main character
	 */
	public void setPlayer(Person player){
		LOGGER.debug(player + " retrieved from the Controller.");
		this.player = player;
	}

	/**
	 * Set the group of people (besides the main character)
	 * who are in the party
	 * @param members People to become the party
	 */
	public void setMembers(List<Person> members){
		this.members = members;
		LOGGER.debug("members in Controller changed to: " + members);
	}
	
	/**
	 * Set the inventory the party is using to store their items
	 * @param inv the inventory to be used
	 */
	public void setInv(Inventory inv){
		this.inv = inv;
		LOGGER.debug("\nInventory in Controller now cointains:\n" + inv);
	}
	
	/**
	 * Set the pace at which the ship moves through time
	 * @param pace the speed of the space ship
	 */
	public void setPace(TravelSpeed pace){
		this.pace = pace;
		LOGGER.debug("Pace in Controller changed to " + pace);
	}
	
	/**
	 * Set the rate at which the party consumes food
	 * @param rations the rate for them to consume at
	 */
	public void setRations(ConsumptionRate rations){
		this.rations = rations;
		LOGGER.debug("Rations in Controller changed to " + rations);
	}
	
	/**
	 * Set the space ship that the party is using to travel
	 * @param ship the ship to become the party's ship
	 */
	public void setShip(Spaceship ship){
		this.ship = ship;
		LOGGER.debug("Spaceship in Controller changed to " + ship);
	}
	
	/**
	 * Returns a string representation for Controller
	 * @return player, inv, pace, rations, and ship's toString
	 */
	@Override
	public String toString(){
		return "Controller: " + player + " " + inv + " " + pace + " "
	            + rations + " " + ship;
	}
}
